clear
clc
close all

file = 'danji';
load_system([file,'/KP']);%加载simulink模块

tic
set_param([file,'/KP'],'value',num2str(0.9014));
set_param([file,'/KI'],'value',num2str(0.0921));
set_param([file,'/KD'],'value',num2str(0.6991));
result = sim('danji.slx',[0 50]);%从0到10s模拟
set_point=23;%目标压力
p = result.ScopeData1.signals.values;
t = result.tout;
toc

S = stepinfo(p,t,set_point,'SettlingTimeThreshold',0.01);
stable_time = S.TransientTime;%调整时间 这个毫无疑问是一个优化目标！
it = find(abs(t-stable_time)<0.1);
ave_error = mean(abs(p(it(end):end)-set_point));%稳态误差
peak = S.Peak;